package com.lcsuo.credit.action;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lcsuo.credit.entity.CompanySummary;
import com.lcsuo.credit.service.CompanysummaryService;

@RestController
public class CompanysummaryController {

	@Autowired
	private CompanysummaryService companysummaryService;
	
	@GetMapping("/test")
	public boolean updateBanlance(String companyCode,BigDecimal balance,HttpServletResponse response) {
		
		boolean sucessed = companysummaryService.updateBalance(companyCode, balance);
		if(sucessed) {
			return true;
		}else {
			response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
			return false;
		}
	}
	
	@GetMapping("/list")
	public List<CompanySummary>  findAll(HttpServletResponse response) throws IOException {
		 try {
			return companysummaryService.findAll();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
		}
		
		 return null;
	}
	
	
}
